﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Tomato.App
{
    public class ErrorResult : JsonResult
    {
        public ErrorResult()
        {
            StatusCode = 500;
        }

        public int StatusCode { get; set; }

        public string Message { get; set; }

        public string Description { get; set; }


        private ServiceError GetAjaxError()
        {
            return new ServiceError() { StatusCode = StatusCode, Message = Message, Description = Description };
        }

        public override void ExecuteResult(ControllerContext context)
        {
            Data = GetAjaxError();
            JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet;

            ((Controller)context.Controller).Response.StatusCode = StatusCode;

            base.ExecuteResult(context);
        }
    }
}
